#!/bin/sh
LOOP_COUNT=10000

case1()
{
	echo "stress status test"
	aspeed-pfr-tool -s > /tmp/src
	i=0
	while [ $i -lt $LOOP_COUNT ]; do
		aspeed-pfr-tool -E -s > /tmp/test
		if ! diff /tmp/src /tmp/test > /dev/null;then
			echo "test case failed at $i rounds"
			exit 1
		fi
		i=$(($i+1))
	done
	echo "stress status test passed"

	echo "stress info test"
	aspeed-pfr-tool -i > /tmp/src
	i=0
	while [ $i -lt $LOOP_COUNT ]; do
		aspeed-pfr-tool -E -i > /tmp/test
		if ! diff /tmp/src /tmp/test > /dev/null;then
			echo "test case failed at $i rounds"
			exit 1
		fi
		i=$(($i+1))
	done
	echo "stress info test passed"

	echo "stress show test"
	aspeed-pfr-tool -p show > /tmp/src
	i=0
	while [ $i -lt $LOOP_COUNT ]; do
		aspeed-pfr-tool -E -p show > /tmp/test
		if ! diff /tmp/src /tmp/test > /dev/null;then
			echo "test case failed at $i rounds"
			exit 1
		fi
		i=$(($i+1))
	done
	echo "stress show test passed"
}

case2()
{
	#to create a secure session from PCH channel
	aspeed-pfr-tool -n 3 -E -t 2 &
	sleep 10
	#to create a secure session from BMC channel
	aspeed-pfr-tool -E -t 2
	echo "two concurrent secure sessions test is done"
}

help()
{
	echo "Usage:"
	echo "secure-test [case1|case2|all]"
}

case $1 in

	case1)
		case1
	;;

	case2)
		case2
	;;

	all)
		case1
		case2
	;;

	*)
		help
	;;
esac

